// JavaScript Document
/********************************************************************/
/* Function Click Check whole row */
/********************************************************************/
function viewProduct()
{
	with (window.document.frmlist) {
		if (cboCategory.selectedIndex == 0) {
			window.location.href = 'index.php';
		} else {
			window.location.href = 'index.php?catId=' + cboCategory.options[cboCategory.selectedIndex].value;
		}
	}
}

function viewByNumPage()
{
	with (window.document.frmlist) {
		if (numpage.selectedIndex != 0) {
			window.location.href = 'index.php?num=' + numpage.options[numpage.selectedIndex].value;
		}
	}
}
function viewEditByNumPage()
{
	with (window.document.frmeditprice) {
		if (numpage.selectedIndex != 0) {
			window.location.href = 'editProductPrice.php?num=' + numpage.options[numpage.selectedIndex].value;
		}
	}
}
function deleteImage(id)
{
	if (confirm('Delete this image')) {
		window.location.href = 'process.php?action=deleteImage&id=' + id;
	}
}
function clickcheckbox(id)
 {
	 document.getElementById("chk"+id).click();
 }
 
function checkAll(frm, value){
	var elm = frm.elements;
	var l_elm = elm.length;
	
	for(i=0; i<l_elm; i++){
		if(elm[i].type == "checkbox"){
			elm[i].checked=value;
		}
	}
} 
/********************************************************************/
/* Function Move Ordering row */
/********************************************************************/
 function drag_drop_row(order_field)
  {
	$(document).ready(function() {
    // Initialise the table
    $("#myTable").tableDnD({ dragHandle: "dragHandle" });
	$("#myTable tr").hover(function() {
          $(this.cells[order_field]).addClass('showDragHandle');
    }, function() {
          $(this.cells[order_field]).removeClass('showDragHandle');
    	});
	});  
  }
	
function Save_Order(){
	var rows = document.getElementById('myTable').tBodies[0].rows;
	var debugStr = '';
		
	for (var i=0; i<rows.length; i++) {
		debugStr += rows[i].id+" ";
	}
	document.frmOrder.hid_order.value=debugStr;
	document.frmOrder.submit();
}

function checkeditems(frm){
	 var val = false;
     var objFormElements = frm.elements;
     for(i=0;i<objFormElements.length;i++){
          if(objFormElements[i].type =="checkbox"){
              if(objFormElements[i].checked==true){
				val=true;
			  }
          }
      }
	  
	  if(val){
		return val;  		
      }
	  else{
      	alert("Please select product category");
		return val;
	}
}

function viewByCategory()
{
	with (window.document.frmlist) {
		if (cate.selectedIndex != 0) {
/*			window.location.href = 'index.php';
		} else {*/
			window.location.href = 'index.php?cateSelect=' + cate.options[cate.selectedIndex].value;
		}
	}
}

///*
//function saveorder( n ) {
//	/*checkAll_button( n );*/
//	submitform('saveorder');
//}
//
////needed by saveorder function
//function checkAll_button( n ) {
//	for ( var j = 0; j <= n; j++ ) {
//		box = eval( "document.frmmenu.cb" + j );
//		if ( box ) {
//			if ( box.checked == false ) {
//				box.checked = true;
//			}
//		} else {
//			alert("You cannot change the order of items, as an item in the list is `Checked Out`");
//			return;
//		}
//	}
//	submitform('saveorder');
//}
///**
//* Submit the admin form
//*/
//function submitform(pressbutton){
//	document.frmmenu.task.value=pressbutton;
//	try {
//		document.frmmenu.onsubmit();
//		}
//	catch(e){}
//	document.frmmenu.submit();
//}
//*/

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}
/****************************************************************/
/* Function Change color row when over on recorde row           */
/****************************************************************/
function ColorOverRow(row,id)
 {
	row.style.background='#f9f9f9';
 }
function ColorOutRow(row,id)
 {
	row.style.background='#FFFFFF';
 }
 
 /********************************************************************/
/* Function Update State or Enabled When Click Publish or Unpublish */
/********************************************************************/
function applyitem(frm,qstr)
{
	qstr = (qstr!="")?"&"+qstr:qstr;
	if(frm){
		frm.action = "process.php?action=apply" + qstr;
		frm.submit();
	
		
	}
}

function EditSelected(frm,qstr,text,itemName)
{
	qstr = (qstr!="")?"&"+qstr:qstr;
	if(confirmEditcheckeditems(itemName,text,frm)){
		frm.action = "index.php?view=add" + qstr;
		frm.submit();
		
	}
}

function confirmEditcheckeditems(itemnm,text,frm){
	 var val = false;
     var objFormElements = frm.elements;
     for(i=0;i<objFormElements.length;i++){
          if(objFormElements[i].type =="checkbox" && objFormElements[i].disabled == false){
              if(objFormElements[i].checked==true){
				val=true;
			  }
          }
      }

	  if(val){
      	return true;//confirm('Are you sure want to Publish the selected '+ itemnm +'?'); 
      }
	  else{
		alert(text);
		return false;  
	  }
}
function publishSelected(frm,qstr,text,publish,itemName,actionFile)
{
	
	qstr = (qstr!="")?"&"+qstr:qstr;
	if(confirmcheckeditems(itemName,frm,text)){	
		frm.action=actionFile+".php?action=publish&publish=" + publish+ qstr;
		frm.submit();
		
	}
}
//Confirm edit more items
function confirmcheckeditems(itemnm,frm,text){
	 var val = false;
     var objFormElements = frm.elements;
     for(i=0;i<objFormElements.length;i++){
          if(objFormElements[i].type =="checkbox" && objFormElements[i].disabled == false){
              if(objFormElements[i].checked==true){
				val=true;
			  }
          }
      }

	  if(val){
      	return true;//confirm('Are you sure want to Publish the selected '+ itemnm +'?'); 
      }
	  else{
		alert(text);
		return false;  
	  }
}
/*
Function to delete the selected item
Form, Query String, Item Name and File to run
*/
function deleteSelected(frm,qstr,itemName,actionFile)
{

	qstr = (qstr!="")?"&"+qstr:qstr;
	if(confirmdelcheckeditems(itemName,frm)){
		frm.action=actionFile+".php?action=delselected" + qstr;
		frm.submit();
	}
}

function deleteSelectedPre(frm,qstr,itemName,actionFile)
{

	qstr = (qstr!="")?"&"+qstr:qstr;
	if(confirmdelcheckeditems(itemName,frm)){
		frm.action=actionFile+".php?action=delselectedPre" + qstr;
		frm.submit();
	}
}

//Confirm delete more items
function confirmdelcheckeditems(itemnm,frm){
	 var val = false;
     var objFormElements = frm.elements;
     for(i=0;i<objFormElements.length;i++){
          if(objFormElements[i].type =="checkbox" && objFormElements[i].disabled == false){
              if(objFormElements[i].checked==true){
				val=true;
			  }
          }
      }

	  if(val){
      	return confirm('Are you sure want to Delete the selected '+ itemnm +'?'); 
      }
	  else{
		alert("No item is selected for Deleting!");
		return false;  
	  }
}





//***********************************************************
//***********************************************************

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}